import Vue from 'vue'
import router from './router'
import store from './store'
import AppLayout from './components/AppLayout.vue'
import './global-components'
import VueFetch, { $fetch } from './plugin/fetch'
import VueState from './plugin/state'
import state from './state'
import * as filters from './filters'

Vue.config.productionTip = false

// 给fetch插件传送一个 baseURL参数过去
Vue.use(VueFetch, {
  baseUrl: 'http://localhost:3000/'
})

Vue.use(VueState, state)

console.log(filters)

for (const key in filters) {
  Vue.filter(key, filters[key])
}

async function main() {
  // 获取用户信息
  try {
    // 如果登录，user接口可以获取到登录用户的信息
    state.user = await $fetch('user')
  } catch (error) {
    console.warn(error)
  }
  // 启动应用
  new Vue({
    router,
    store,
    data: state,
    render: h => h(AppLayout)
  }).$mount('#app')
}

main()